﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework.Graphics;
using Box2D.XNA;

public class Mobby : Sprite
{
    
    public Mobby(Vector2 position, String [] filenames, Game game, ushort mask) : base(position, filenames, game, mask)
	{
        /*
        panelWidth = 150;
        panelLength = 220;
        panelDimensionX = 27;
        panelDimensionY = 16;
        */

        spriteSheets.Add("main", new SpriteSheet(game.Content.Load<Texture2D>(filenames[0]), 75, 110, 27, 16));
        spriteSheets.Add("attack", new SpriteSheet(game.Content.Load<Texture2D>(filenames[1]), 207/2, 220/2, 7, 3));

        stateSpriteSheetMap.Add("stand", "main");
        stateSpriteSheetMap.Add("initWalkR", "main");
        stateSpriteSheetMap.Add("initWalkL", "main");
        stateSpriteSheetMap.Add("walkR", "main");
        stateSpriteSheetMap.Add("walkL", "main");
        stateSpriteSheetMap.Add("initRunR", "main");
        stateSpriteSheetMap.Add("initRunL", "main");
        stateSpriteSheetMap.Add("runR", "main");
        stateSpriteSheetMap.Add("runL", "main");
        stateSpriteSheetMap.Add("runR-walkL", "main");
        stateSpriteSheetMap.Add("runL-walkR", "main");
        stateSpriteSheetMap.Add("jumpR", "main");
        stateSpriteSheetMap.Add("jumpL", "main");
        stateSpriteSheetMap.Add("rollR", "main");
        stateSpriteSheetMap.Add("rollL", "main");
        stateSpriteSheetMap.Add("attackR", "attack");
        stateSpriteSheetMap.Add("attackL", "attack");
        stateSpriteSheetMap.Add("jumpAttackR", "attack");
        stateSpriteSheetMap.Add("jumpAttackL", "attack");
        stateSpriteSheetMap.Add("runAttackR", "attack");
        stateSpriteSheetMap.Add("runAttackL", "attack");

        BodyDef bodyDef = new BodyDef();
        bodyDef.type = BodyType.Dynamic;
        bodyDef.position = position;
        spriteBody = game.getWorld().CreateBody(bodyDef);

        PolygonShape dynamicBox = new PolygonShape();
        dynamicBox.SetAsBox(getPanelWidth()/2-10, getPanelLength()/2-10);

        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = dynamicBox;
        fixtureDef.density = .000002f;
        spriteBody.ResetMassData();
        fixtureDef.friction = .0f;
        fixtureDef.userData = this;

        fixtureDef.filter.categoryBits = (ushort)(0xF - mask);

        spriteBody.CreateFixture(fixtureDef);

        SortedDictionary<int, double> stand = new SortedDictionary<int, double>();
        stand.Add(0, 1.0);
        stand.Add(1, 1.0);
        stand.Add(2, 1.0);
        animations.Add("stand", stand);

        SortedDictionary<int, double> initWalkR = new SortedDictionary<int, double>();
        initWalkR.Add(3, .3);
        animations.Add("initWalkR", initWalkR);

        SortedDictionary<int, double> initWalkL = new SortedDictionary<int, double>();
        initWalkL.Add(3, .3);
        animations.Add("initWalkL", initWalkL);

        SortedDictionary<int, double> walkR = new SortedDictionary<int, double>();
        walkR.Add(4, .3);
        walkR.Add(5, .3);
        walkR.Add(6, .3);
        walkR.Add(7, .3);
        animations.Add("walkR", walkR);

        SortedDictionary<int, double> walkL = new SortedDictionary<int, double>();
        walkL.Add(4+27, .3);
        walkL.Add(5+27, .3);
        walkL.Add(6+27, .3);
        walkL.Add(7+27, .3);
        animations.Add("walkL", walkL);

        SortedDictionary<int, double> initRunR = new SortedDictionary<int, double>();
        initRunR.Add(9, .3);
        initRunR.Add(10, .3);
        animations.Add("initRunR", initRunR);

        SortedDictionary<int, double> initRunL = new SortedDictionary<int, double>();
        initRunL.Add(9 + 27, .3);
        initRunL.Add(10 + 27, .3);
        animations.Add("initRunL", initRunL);

        SortedDictionary<int, double> runR = new SortedDictionary<int, double>();
        runR.Add(11, .3);
        runR.Add(12, .3);
        runR.Add(13, .3);
        runR.Add(14, .3);
        runR.Add(15, .3);
        animations.Add("runR", runR);

        SortedDictionary<int, double> runL = new SortedDictionary<int, double>();
        runL.Add(11+27, .3);
        runL.Add(12+27, .3);
        runL.Add(13+27, .3);
        runL.Add(14+27, .3);
        runL.Add(15+27, .3);
        animations.Add("runL", runL);

        //using stand frames for run-walk for now
        SortedDictionary<int, double> runWalkL = new SortedDictionary<int, double>();
        runWalkL.Add(0, .3);
        runWalkL.Add(1, .3);
        runWalkL.Add(2, .3);
        animations.Add("runR-walkL", runWalkL);

        SortedDictionary<int, double> runWalkR = new SortedDictionary<int, double>();
        runWalkR.Add(0, .3);
        runWalkR.Add(1, .3);
        runWalkR.Add(2, .3);
        animations.Add("runL-walkR", runWalkR);

        SortedDictionary<int, double> jumpR = new SortedDictionary<int, double>();
        jumpR.Add(19, .3);
        jumpR.Add(20, .3);
        jumpR.Add(21, .3);
        jumpR.Add(22, .3);
        jumpR.Add(23, .3);
        jumpR.Add(24, .3);
        jumpR.Add(25, .3);
        animations.Add("jumpR", jumpR);

        SortedDictionary<int, double> jumpL = new SortedDictionary<int, double>();
        jumpL.Add(19+27, .3);
        jumpL.Add(20+27, .3);
        jumpL.Add(21+27, .3);
        jumpL.Add(22+27, .3);
        jumpL.Add(23+27, .3);
        jumpL.Add(24+27, .3);
        jumpL.Add(25+27, .3);
        animations.Add("jumpL", jumpL);

        SortedDictionary<int, double> rollR = new SortedDictionary<int, double>();
        rollR.Add(0, .3);
        rollR.Add(1, .3);
        rollR.Add(2, .3);
        animations.Add("rollR", rollR);

        SortedDictionary<int, double> rollL = new SortedDictionary<int, double>();
        rollL.Add(0, .3);
        rollL.Add(1, .3);
        rollL.Add(2, .3);
        animations.Add("rollL", rollL);

        SortedDictionary<int, double> attackR = new SortedDictionary<int, double>();
        attackR.Add(0, .1);
        attackR.Add(1, .1);
        attackR.Add(2, .1);
        attackR.Add(3, .1);
        attackR.Add(4, .1);
        attackR.Add(5, .1);
        animations.Add("attackR", attackR);


        SortedDictionary<int, double> attackL = new SortedDictionary<int, double>();
        attackL.Add(21 + 0, .1);
        attackL.Add(21 + 1, .1);
        attackL.Add(21 + 2, .1);
        attackL.Add(21 + 3, .1);
        attackL.Add(21 + 4, .1);
        attackL.Add(21 + 5, .1);
        animations.Add("attackL", attackL);

        SortedDictionary<int, double> jumpAttackR = new SortedDictionary<int, double>();
        jumpAttackR.Add(7 + 0, .2);
        jumpAttackR.Add(7 + 1, .2);
        jumpAttackR.Add(7 + 2, .2);
        jumpAttackR.Add(7 + 3, .2);
        jumpAttackR.Add(7 + 4, .2);
        jumpAttackR.Add(7 + 5, .1);
        jumpAttackR.Add(7 + 6, .1);
        animations.Add("jumpAttackR", jumpAttackR);

        SortedDictionary<int, double> jumpAttackL = new SortedDictionary<int, double>();
        jumpAttackL.Add(28 + 0, .2);
        jumpAttackL.Add(28 + 1, .2);
        jumpAttackL.Add(28 + 2, .2);
        jumpAttackL.Add(28 + 3, .2);
        jumpAttackL.Add(28 + 4, .2);
        jumpAttackL.Add(28 + 5, .1);
        jumpAttackL.Add(28 + 6, .1);
        animations.Add("jumpAttackL", jumpAttackL);

        SortedDictionary<int, double> runAttackR = new SortedDictionary<int, double>();
        runAttackR.Add(14 + 0, .3);
        runAttackR.Add(14 + 1, .3);
        runAttackR.Add(14 + 2, .3);
        animations.Add("runAttackR", runAttackR);

        SortedDictionary<int, double> runAttackL = new SortedDictionary<int, double>();
        runAttackL.Add(35 + 0, .3);
        runAttackL.Add(35 + 1, .3);
        runAttackL.Add(35 + 2, .3);
        animations.Add("runAttackL", runAttackL);

        Dictionary <string, SortedDictionary<int, double>> animations2 = new Dictionary<string, SortedDictionary<int, double>>(animations);
        foreach (KeyValuePair <string, SortedDictionary<int, double>> animation in animations)
        {
            SortedDictionary<int, double> animation2 = new SortedDictionary<int, double>(animation.Value);
            foreach (KeyValuePair <int, double> frame in animation2)
            {
                animations[animation.Key][frame.Key] = frame.Value/1.5;
            }
        }

        //collision boxes
        collisionObjects = new Dictionary<KeyValuePair<string, int>, CollisionInfo>();
        //attackR
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 0), new CollisionInfo(-23, 25, 30, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 1), new CollisionInfo(-23, 25, 35, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 2), new CollisionInfo(-17, 25, 30, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 3), new CollisionInfo(0, 30, 30, 50));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 4), new CollisionInfo(35, 15, 35, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 5), new CollisionInfo(30, -15, 50, 20));

        //jumpAttackR
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 7), new CollisionInfo(-25, 30, 30, 35));
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 8), new CollisionInfo(-30, 0, 45, 20));
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 9), new CollisionInfo(30, -15, 30, 35));
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 10), new CollisionInfo(20, 35, 30, 40));

        //runAttackR
        collisionObjects.Add(new KeyValuePair<string, int>("runAttackR", 14), new CollisionInfo(25, 35, 35, 35));
        collisionObjects.Add(new KeyValuePair<string, int>("runAttackR", 15), new CollisionInfo(30, 15, 45, 20));
        collisionObjects.Add(new KeyValuePair<string, int>("runAttackR", 16), new CollisionInfo(30, 15, 45, 20));

        //attackL
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 0 + 21), new CollisionInfo(23, 25, 30, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 1 + 21), new CollisionInfo(23, 25, 35, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 2 + 21), new CollisionInfo(17, 25, 30, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 3 + 21), new CollisionInfo(0, 30, 30, 50));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 4 + 21), new CollisionInfo(-35, 15, 35, 40));
        collisionObjects.Add(new KeyValuePair<string, int>("attackR", 5 + 21), new CollisionInfo(-30, -15, 50, 20));

        //jumpAttackL
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 7 + 28), new CollisionInfo(25, 30, 30, 35));
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 8 + 28), new CollisionInfo(30, 0, 45, 20));
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 9 + 28), new CollisionInfo(-30, -15, 30, 35));
        collisionObjects.Add(new KeyValuePair<string, int>("jumpAttackR", 10 + 28), new CollisionInfo(-20, 35, 30, 40));

        //runAttackL
        collisionObjects.Add(new KeyValuePair<string, int>("runAttackR", 14 + 35), new CollisionInfo(-25, 35, 35, 35));
        collisionObjects.Add(new KeyValuePair<string, int>("runAttackR", 15 + 35), new CollisionInfo(-30, 15, 45, 20));
        collisionObjects.Add(new KeyValuePair<string, int>("runAttackR", 16 + 35), new CollisionInfo(-30, 15, 45, 20));
        
    }

    //code for standing, walking, and running
    override public void update(GameTime gameTime, List<ButtonAction> buttonsPressed)
    {
        //should have speeds stored in dict with keys being states (string)
        float scale = 1000.0f;
        float runAccel = scale * 2;
        float walkAccel = scale * .5f;
        float runWalkAccel = scale * 3;
        float runStandAccel = scale * 2;
        float walkStandAccel = scale * 2;
        float jumpHorVel = scale * 10;
        float jumpVertVel = -scale * 20;
        float jumpVertDecel = jumpVertVel * 2 / 62;
        float rollMinVel = scale * 45;
        float rollVelScale = 1;

        bool updateFrame = false;

        animationTime += gameTime.ElapsedGameTime.TotalSeconds;
        if (animationTime >= animations[state][animationFrame])
        {
            animationTime -= animations[state][animationFrame];
            updateFrame = true;
        }

        //rollR
        if ((state == "stand" || state == "walkR" || state == "runR" || state == "initRunR")
            && buttonsPressed.Contains(ButtonAction.Roll) && buttonsPressed.Contains(ButtonAction.Right))
        {
            state = "rollR";
            facing = Facing.Right;
            if (spriteBody.GetLinearVelocity().X < rollMinVel)
                spriteBody.SetLinearVelocity(new Vector2(rollMinVel, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["rollR"].First().Key;
            updateFrame = false;
        }
        else if (state == "rollR" && animations["rollR"].Last().Key <= animationFrame && updateFrame)
        {
            spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X / rollVelScale, spriteBody.GetLinearVelocity().Y));
            state = "walkR";
            spriteBody.ApplyForce(new Vector2(walkAccel, 0.0f), spriteBody.GetWorldCenter());
            animationFrame = animations["walkR"].First().Key;
            updateFrame = false;
        }
        //rollL
        else if ((state == "stand" || state == "walkL" || state == "runL" || state == "initRunL")
            && buttonsPressed.Contains(ButtonAction.Roll) && buttonsPressed.Contains(ButtonAction.Left))
        {
            state = "rollL";
            facing = Facing.Left;
            if (spriteBody.GetLinearVelocity().X > -rollMinVel)
                spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X - rollMinVel, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["rollL"].First().Key;
            updateFrame = false;
        }
        else if (state == "rollL" && animations["rollL"].Last().Key <= animationFrame && updateFrame)
        {
            spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X / rollVelScale, spriteBody.GetLinearVelocity().Y));
            state = "walkL";
            spriteBody.ApplyForce(new Vector2(-walkAccel, 0.0f), spriteBody.GetWorldCenter());
            animationFrame = animations["walkL"].First().Key;
            updateFrame = false;
        }
        //runR
        else if ((state == "stand" || (state == "walkR" && spriteBody.GetLinearVelocity().X >= 0) || state == "walkL")
            && ((buttonsPressed.Contains(ButtonAction.Right) && buttonsPressed.Contains(ButtonAction.Boost)) || buttonsPressed.Contains(ButtonAction.HardRight)))
        {
            state = "initRunR";
            //accelerationX = runAccel;
            spriteBody.ApplyForce(new Vector2(runAccel, 0.0f), spriteBody.GetWorldCenter());
            facing = Facing.Right;
            animationFrame = animations["initRunR"].First().Key;
            updateFrame = false;
        }
        else if (state == "initRunR" && animations["initRunR"].Last().Key <= animationFrame && updateFrame)
        {
            state = "runR";
            animationFrame = animations["runR"].First().Key;
            updateFrame = false;

        }
        else if (state == "runR" && buttonsPressed.Contains(ButtonAction.Left))
        {
            //have stand replace turning anim for now
            state = "runR-walkL";
            //accelerationX = -runWalkAccel;
            spriteBody.ApplyForce(new Vector2(-runWalkAccel, 0.0f), spriteBody.GetWorldCenter());
            facing = Facing.Left;
            animationFrame = animations["runR-walkL"].First().Key;
            updateFrame = false;
        }

        //runL
        else if ((state == "stand" || (state == "walkR" && spriteBody.GetLinearVelocity().X >= 0) || state == "walkL")
            && ((buttonsPressed.Contains(ButtonAction.Left) && buttonsPressed.Contains(ButtonAction.Boost)) || buttonsPressed.Contains(ButtonAction.HardLeft)))
        {
            state = "initRunL";
            //accelerationX = -runAccel;
            spriteBody.ApplyForce(new Vector2(-runAccel, 0.0f), spriteBody.GetWorldCenter());
            facing = Facing.Left;
            animationFrame = animations["initRunL"].First().Key;
            updateFrame = false;
        }
        else if (state == "initRunL" && animations["initRunL"].Last().Key <= animationFrame && updateFrame)
        {
            state = "runL";
            animationFrame = animations["runL"].First().Key;
            updateFrame = false;
        }
        else if (state == "runL" && buttonsPressed.Contains(ButtonAction.Right))
        {
            //have stand replace turning anim for now
            state = "runL-walkR";
            //accelerationX = runWalkAccel;
            spriteBody.ApplyForce(new Vector2(runWalkAccel, 0.0f), spriteBody.GetWorldCenter());
            facing = Facing.Right;
            animationFrame = animations["runL-walkR"].First().Key;
            updateFrame = false;
        }
        //jumpAttackR
        else if (state == "jumpR" && buttonsPressed.Contains(ButtonAction.Attack))
        {
            state = "jumpAttackR";
            animationFrame = animations["jumpAttackR"].First().Key + (animationFrame - animations["jumpR"].First().Key);
        }
        //jumpAttackL
        else if (state == "jumpL" && buttonsPressed.Contains(ButtonAction.Attack))
        {
            state = "jumpAttackL";
            animationFrame = animations["jumpAttackL"].First().Key + (animationFrame - animations["jumpL"].First().Key);
        }
        else if (buttonsPressed.Contains(ButtonAction.Jump) && buttonsPressed.Contains(ButtonAction.Roll))
            state = state;
        //jumpR
        else if ((state == "stand" || state == "walkR" || state == "runR" || state == "initRunR")
            && buttonsPressed.Contains(ButtonAction.Right) && buttonsPressed.Contains(ButtonAction.Jump))
        {
            state = "jumpR";
            if (spriteBody.GetLinearVelocity().X < jumpHorVel)
            {
                spriteBody.SetLinearVelocity(new Vector2(jumpHorVel, spriteBody.GetLinearVelocity().Y));
            }
            //accelerationY = -jumpVertDecel;
            //velocityY = jumpVertVel;
            spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X, jumpVertVel));
            facing = Facing.Right;
            animationFrame = animations["jumpR"].First().Key;
            updateFrame = false;
        }
        else if (((state == "jumpR" && animationFrame >= animations["jumpR"].Last().Key)
            || (state == "jumpAttackR" && animationFrame >= animations["jumpAttackR"].Last().Key)) && updateFrame)
        {
            state = "walkR";
            spriteBody.SetLinearVelocity(new Vector2(0.0f, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["walkR"].First().Key;
            updateFrame = false;
        }
        //jumpL
        else if ((state == "stand" || state == "walkL" || state == "runL" || state == "initRunR")
            && buttonsPressed.Contains(ButtonAction.Left) && buttonsPressed.Contains(ButtonAction.Jump))
        {
            state = "jumpL";
            //if (velocityX > -jumpHorVel)
            //{
            //  velocityX = -jumpHorVel;
            //}
            state = "jumpL";
            if (spriteBody.GetLinearVelocity().X > -jumpHorVel)
            {
                spriteBody.SetLinearVelocity(new Vector2(-jumpHorVel, spriteBody.GetLinearVelocity().Y));
            }

            //accelerationY = -jumpVertDecel;
            //velocityY = jumpVertVel;
            spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X, jumpVertVel));
            facing = Facing.Left;
            animationFrame = animations["jumpL"].First().Key;
            updateFrame = false;
        }
        else if (((state == "jumpL" && animationFrame >= animations["jumpL"].Last().Key)
            || (state == "jumpAttackL" && animationFrame >= animations["jumpAttackL"].Last().Key)) && updateFrame)
        {
            state = "walkL";
            //accelerationY = 0;
            //velocityY = 0;
            animationFrame = animations["walkL"].First().Key;
            updateFrame = false;
        }
        //runAttackR
        else if (state == "runR" && buttonsPressed.Contains(ButtonAction.Attack))
        {
            state = "runAttackR";
            animationFrame = animations["runAttackR"].First().Key;
            updateFrame = false;
        }
        else if (state == "runAttackR" && animationFrame >= animations["runAttackR"].Last().Key)
        {
            state = "runR";
            //velocityX /= 2;
            spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X / 2, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["runR"].First().Key;
            updateFrame = false;
        }
        //runAttackL
        else if (state == "runL" && buttonsPressed.Contains(ButtonAction.Attack))
        {
            state = "runAttackL";
            animationFrame = animations["runAttackL"].First().Key;
            updateFrame = false;
        }
        else if (state == "runAttackL" && animationFrame >= animations["runAttackL"].Last().Key)
        {
            state = "runL";
            //velocityX /= 2;
            spriteBody.SetLinearVelocity(new Vector2(spriteBody.GetLinearVelocity().X / 2, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["runL"].First().Key;
            updateFrame = false;
        }
        //attackR
        else if (((state == "stand" && facing == Facing.Right) || state == "walkR") && buttonsPressed.Contains(ButtonAction.Attack))
        {
            state = "attackR";
            //accelerationX = 0;
            //velocityX = 0;
            spriteBody.SetLinearVelocity(new Vector2(0, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["attackR"].First().Key;
            updateFrame = false;
        }
        //attackL
        else if (((state == "stand" && facing == Facing.Left) || state == "walkL") && buttonsPressed.Contains(ButtonAction.Attack))
        {
            state = "attackL";
            //accelerationX = 0;
            //velocityX = 0;
            spriteBody.SetLinearVelocity(new Vector2(0, spriteBody.GetLinearVelocity().Y));
            animationFrame = animations["attackL"].First().Key;
            updateFrame = false;
        }
        //walkR
        else if (((state == "stand" || (state == "walkL" && spriteBody.GetLinearVelocity().X >= 0)) && buttonsPressed.Contains(ButtonAction.Right)) || (state == "runL-walkR" && spriteBody.GetLinearVelocity().X >= 0)
            || (state == "runR" && spriteBody.GetLinearVelocity().X <= 5 && buttonsPressed.Contains(ButtonAction.Right)
            && !buttonsPressed.Contains(ButtonAction.Boost)))//should replace 5 with walk's top speed
        {
            state = "walkR";
            //accelerationX = walkAccel;
            spriteBody.ApplyForce(new Vector2(walkAccel, 0.0f), spriteBody.GetWorldCenter());
            facing = Facing.Right;
            animationFrame = animations["walkR"].First().Key;
            updateFrame = false;
        }
        else if (state == "walkL" && buttonsPressed.Contains(ButtonAction.Right))
        {
            //accelerationX = 0;
            spriteBody.ApplyForce(new Vector2(0, 0.0f), spriteBody.GetWorldCenter());
            //velocityX = 0;
            spriteBody.SetLinearVelocity(new Vector2(0));
        }
        else if (state == "runR" && buttonsPressed.Contains(ButtonAction.Right) && !buttonsPressed.Contains(ButtonAction.Boost))
        {
            //accelerationX = -runStandAccel;
            spriteBody.ApplyForce(new Vector2(-runStandAccel, 0.0f), spriteBody.GetWorldCenter());
        }
        //walkL
        else if (((state == "stand" || (state == "walkR" && spriteBody.GetLinearVelocity().X <= 0)) && buttonsPressed.Contains(ButtonAction.Left)) || (state == "runR-walkL" && spriteBody.GetLinearVelocity().X <= 0)
            || (state == "runL" && spriteBody.GetLinearVelocity().X >= -5 && buttonsPressed.Contains(ButtonAction.Left)
            && !buttonsPressed.Contains(ButtonAction.Boost)))//should replace 5 with walk's top speed
        {
            state = "walkL";
            //accelerationX = -walkAccel;
            spriteBody.ApplyForce(new Vector2(-walkAccel, 0.0f), spriteBody.GetWorldCenter());
            facing = Facing.Left;
            animationFrame = animations["walkL"].First().Key;
            updateFrame = false;
        }
        else if (state == "walkR" && buttonsPressed.Contains(ButtonAction.Left))
        {
            //accelerationX = 0;
            spriteBody.ApplyForce(new Vector2(0, 0.0f), spriteBody.GetWorldCenter());
            //velocityX = 0;
            spriteBody.SetLinearVelocity(new Vector2(0));
        }
        else if (state == "runR" && buttonsPressed.Contains(ButtonAction.Left) && !buttonsPressed.Contains(ButtonAction.Boost))
        {
            //accelerationX = runStandAccel;
            spriteBody.ApplyForce(new Vector2(runStandAccel, 0.0f), spriteBody.GetWorldCenter());
        }
        //stand
        else if ((state == "walkR" && !buttonsPressed.Contains(ButtonAction.Right) && spriteBody.GetLinearVelocity().X <= 0)
            || (state == "walkL" && !buttonsPressed.Contains(ButtonAction.Left) && spriteBody.GetLinearVelocity().X >= 0)
            || (state == "attackR" && animations["attackR"].Last().Key <= animationFrame && updateFrame)
            || (state == "attackL" && animations["attackL"].Last().Key <= animationFrame && updateFrame))
        {
            state = "stand";
            //accelerationX = 0;
            spriteBody.ApplyForce(new Vector2(0, 0.0f), spriteBody.GetWorldCenter());
            animationFrame = animations["stand"].First().Key;
            updateFrame = false;
        }
        else if (state == "walkR" && !buttonsPressed.Contains(ButtonAction.Right))
        {
            //accelerationX = 0;
            spriteBody.ApplyForce(new Vector2(0, 0.0f), spriteBody.GetWorldCenter());
            //velocityX = 0;
            spriteBody.SetLinearVelocity(new Vector2(0));
        }
        else if (state == "walkL" && !buttonsPressed.Contains(ButtonAction.Left))
        {
            //accelerationX = 0;
            spriteBody.ApplyForce(new Vector2(0, 0.0f), spriteBody.GetWorldCenter());
            //velocityX = 0;
            spriteBody.SetLinearVelocity(new Vector2(0));
        }

        if (updateFrame) animationFrame++;
        if (animationFrame > animations[state].Last().Key)
        {
            animationFrame = animations[state].First().Key;
        }
        
        removeFixtures();
        if (collisionObjects.ContainsKey(new KeyValuePair<string, int>(state, animationFrame)))
        {
            CollisionInfo collInfo = collisionObjects[new KeyValuePair<string, int>(state, animationFrame)];
            addFixture(collInfo.x, collInfo.y, collInfo.width, collInfo.length);
        }
    }
}